package com.hdu.controller.utilManagement;

import com.hdu.entity.Website;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.pojo.Sort;
import com.hdu.service.IWebsiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 网站实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2023-11-01
 */

@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "网站管理接口")
@RequestMapping("/website")
public class WebsiteController {

    private final IWebsiteService websiteService;


    @GetMapping
    @ApiOperation("分页获取网站列表")
    public Result<?> page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "4") Integer limit,
                       String linkName) {
        log.info("分页查询, 参数: {},{},{}", page, limit, linkName);
        //调用service分页查询
        PageBean<Website> pageBean = websiteService.page(page, limit, linkName);
        return Result.success(pageBean);
    }

    @GetMapping("/sort")
    @ApiOperation("分类获取专业列表")
    public Result<?> detail() {
        List<Sort> sortList = websiteService.sortWebsite();
        log.info("网站链接分类查询, sortList: {}", sortList);
        return Result.success(sortList);
    }

    @DeleteMapping
    @ApiOperation("删除网站链接")
    public Result<?> delete(@RequestBody List<String> idList) {
        log.info("删除网站链接, idList:{}", idList);
        websiteService.removeBatchByIds(idList);
        return Result.success();
    }


    @PostMapping
    @ApiOperation("新增网站链接")
    public Result<?> append(@RequestBody Website website) {
        log.info("新增网站链接, link: {}", website);
        websiteService.append(website);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("更新网站链接信息")
    public Result<?> update(@RequestBody Website website) {
        log.info("更新网站链接信息 : {}", website);
        websiteService.updateById(website);
        return Result.success();
    }
}
